var layer = layui.layer //弹层
    ,table = layui.table //表格
    ,form = layui.form,$ = layui.jquery,laydate = layui.laydate,purchaseNo=getQueryVariable("purchaseNo");

layui.use(['tableEdit',"excel"], function () {
    let tableEdit = layui.tableEdit;
    let layer = layui.layer,
        excel = layui.excel;

    lay('.starttime').each(function(){
        laydate.render({
            elem: this
        });
    });
//费用类型
    let allCost=[];
    layer.ready(function () {

        //获取币种
        $.ajax({
            url:"payment/getSupplierInfo",
            success:function(data){
                if(data.status == 200){
                    for(let i in data.data){
                        $('#supplierCode').append(new Option(data.data[i].name, data.data[i].code));
                    }
                    form.render('select');
                }
            }
        });

    });
    form.render();//表单刷新
    let initData = [];
    table.render({
        elem: '#paymentSelect'
        ,data:initData
        ,toolbar: '#paymentToolbar'
        ,totalRow: true
        ,cols: [[
            {field: 'numbers',width: 50,type:'numbers',title:'序号', totalRowText: '合计'},
            {field:'purchaseStr', title:'采购签约日期',sort:true,width: 200},
            {field:'purchaseNo', title:'采购单号',width: 200},
            {field:'createTimeStr', title:'采购单日期',width: 200,sort:true},
            {field:'buyerName', title:'采购员',width: 120},
            {field:'salesContractNo', title:'外销合同号',width: 200},
            {field:'salesmanName', title:'业务员',width: 120},
            {field:'billNo', title:'付款单号',width: 220},
            {field:'supplierName', title:'收款单位',width: 220},
            {field: 'currency',  title: '币种',width: 120},
            {field: 'purchaseTotalPrice', width: 120, title: '采购单总额',sort:true, totalRow: true},
            {field:'applicationTotal', title:'申请金额合计',sort:true,width: 120, totalRow: true},
            {field: 'unApplicationAmount',  title: '未申请金额',width: 120, totalRow: true},
            {field: 'totalAmountActuallyPaid',  title: '实付金额',sort:true,width: 120, totalRow: true},
            // {field: 'unAmount',  title: '未付金额',width: 120, totalRow: true},
            {field:'paidStr', title:'实付日期',sort:true,width: 120},
            {field:'purchaseType', title:'单据类型',width:100},
        ]]
        ,id: 'maininformationtableid'
        ,height: $(document).height() - $('#paymentSelect').offset().top - 75,
        //开启分页
        page: true,
        limits: [300,600,900],
    });

    if (purchaseNo!=""){
        $("#contractPurchaseNumber").val(purchaseNo);
        let data={}
        data.contractPurchaseNumber=purchaseNo;
        table.reload('maininformationtableid', {
            page: {
                limit: 300,
                curr: 1
            },
            url:'payment/paymentStatistics1ListByPage',
            where: data
        }, 'data');
        return false;

    }

    //搜索提交
    form.on('submit(submitform)', function(data){
        table.reload('maininformationtableid', {
            page: {
                limit:300,
                curr: 1
            },
            url:'payment/paymentStatistics1ListByPage',
            where:  data.field
        }, 'data');
        return false;
    });

    form.on('submit(exportData)', function (queryReq) {
        let index = layer.load(2, {
            shade: [0.4, '#000'],
            content: '加载中...',
            success: function (layero) {
                layero.find('.layui-layer-content').css({
                    'padding-top': '40px',
                    'width': '200px'
                });
            }
        });
        $.ajax({
            data: queryReq.field,
            url:"payment/paymentStatistics1ListExport",
            success: function(res) {
                if(res.status == 200){
                    //配置列宽
                    let colConf = excel.makeColConfig({
                        'A': 80,
                        'X': 80
                    }, 80);
                    excel.exportExcel({
                        sheet1: res.data.data
                    }, '付款情况统计.xlsx', 'xlsx', {
                        extend: {
                            '!cols': colConf
                        }
                    });
                }else {
                    layer.msg(res.msg, {icon: 5});
                }
                layer.close(index);
                return false;
            }
        });
        return false;
    });
});

